---------------------------------------
--           AmBPaddedPanel          --
---------------------------------------
-- Simple panel that has a padded child.
local PaddedPanel = {
   Init = function(self)
      self._PaddingAmounts = ThemeVar("default_paddingcontrol_padding_amounts") or {4, 4, 4, 4}
      self._Child = vgui.Create("AmBContentPanel", self)
      self._InnerColor = Color(0, 0, 0, 0)
      self._OuterColor = Color(0, 0, 0, 0)
		function self._Child.OnChildRequestResize(child, NewWidth, NewHeight)
			local l, t, r, b = self:GetPadding()
			return self:RequestResize(NewWidth + l + r, NewHeight + t + b)
		end
   end,

   Paint = function(self)
      local incol = self._InnerColor
      local outcol = self._OuterColor
      if incol.a > 0 or outcol.a > 0 then
         local pad = Freeze(self._PaddingAmounts)
         local width = self:GetWide()
         local height = self:GetTall()
         if incol.r == outcol.r and incol.g == outcol.g and incol.b == outcol.b and incol.a == outcol.a then
            SetSurfaceToColor(incol)
            surface.DrawRect(0, 0, width, pad[2])
            surface.DrawRect(0, height - pad[4], width, pad[4])
            surface.DrawRect(0, pad[2], pad[1], height - (pad[2] + pad[4]))
            surface.DrawRect(width - pad[3], pad[2], pad[3], height - (pad[2] + pad[4]))
         else
            if pad[1] == pad[2] and pad[2] == pad[3] and pad[3] == pad[4] then
               -- Allow blend padding
               pad = pad[1]
               for x = 0, pad do
                  SetSurfaceToBlend(outcol, incol, x / pad)
                  surface.DrawOutlinedRect(x, x, width - (x * 2), height - (x * 2))
               end
            end
         end
      end
      return false
   end,

   -- Sets the colors used on the padding. Note that
   -- blending can only be performed if margins are
   -- all equal.
   SetPaddingColor = function(self, InnerColor, OuterColor)
      self._InnerColor = InnerColor
      self._OuterColor = OuterColor
   end,

   -- Sets the amount of padding used.
   SetPadding = function(self, Left, Up, Right, Down)
		if Up == nil and Right == nil and Down == nil then
			self._PaddingAmounts = Left
		else
			self._PaddingAmounts = {Left, Up, Right, Down}
		end
   end,
	
	-- Gets the padding of this panel as four different values.
	GetPadding = function(self)
		return self._PaddingAmounts[1], self._PaddingAmounts[2], 
			self._PaddingAmounts[3], self._PaddingAmounts[4]
	end,

   -- Gets the padded child panel.
   GetInterior = function(self)
      return self._Child
   end,

   PanelThink = function(self)
      self._Child:SetPos(self._PaddingAmounts[1], self._PaddingAmounts[2])
      self._Child:SetSize(
         self:GetWide() - self._PaddingAmounts[1] - self._PaddingAmounts[3],
         self:GetTall() - self._PaddingAmounts[2] - self._PaddingAmounts[4])
   end
}
AmB.UI.PaddedPanel = PaddedPanel
vgui.Register("AmBPaddedPanel", PaddedPanel, "AmBContentPanel")